package io.terminus.spzx.product.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.terminus.spzx.model.entity.product.Category;
import io.terminus.spzx.model.entity.product.ProductSku;
import io.terminus.spzx.model.vo.common.Result;
import io.terminus.spzx.model.vo.common.ResultCodeEnum;
import io.terminus.spzx.model.vo.h5.IndexVo;
import io.terminus.spzx.product.service.CategoryService;
import io.terminus.spzx.product.service.ProductSkuService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author lichunlong lcl253137@alibaba-inc.com
 * @Desc 移动端首页Controller
 * @Date 2024-10-20
 */
@RestController
@Tag(name = "首页接口管理")
@RequiredArgsConstructor
@RequestMapping(value = "/api/product/index")
public class IndexController {

    private final CategoryService categoryService;

    private final ProductSkuService productSkuService;

    @GetMapping
    @Operation(summary = "获取首页数据")
    public Result<IndexVo> findData() {
        IndexVo indexVo = new IndexVo();
        // 一级分类
        List<Category> categoryList = categoryService.findOneCategory();
        indexVo.setCategoryList(categoryList);
        // 销量排名: 销量前10条排名记录
        List<ProductSku> productSkuList = productSkuService.findProductSkuBySale();
        indexVo.setProductSkuList(productSkuList);

        return Result.build(indexVo, ResultCodeEnum.SUCCESS);
    }

}
